<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Jialeo\LaravelSchemaExtend\Schema;

class AddTemplateTypeToSelfTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('cruise_check_self_task', function (Blueprint $table) {
            $table->unsignedTinyInteger('templateType')->default(0)->comment('模板type 5工厂稽核 8门店自检')->after('id');
        });

        Schema::table('cruise_check_self_task_company_mappings', function (Blueprint $table) {
            $table->unsignedInteger('shopId')->default(0)->comment('门店id')->after('id');
        });

        Schema::table('cruise_check_self_detail', function (Blueprint $table) {
            $table->unsignedTinyInteger('templateType')->default(0)->comment('模板type 5工厂稽核 8门店自检')->after('id');
            $table->unsignedInteger('shopId')->default(0)->comment('门店id')->after('id');
        });

        \App\Models\Cruise\CruiseCheckSelfTaskModel::query()->where('templateType', 0)->update(['templateType' => \App\Models\Cruise\CruiseTemplateModel::TYPE_5]);

        \App\Models\Cruise\CruiseCheckSelfDetailModel::query()->where('templateType', 0)->update(['templateType' => \App\Models\Cruise\CruiseTemplateModel::TYPE_5]);
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('cruise_check_self_task', function (Blueprint $table) {
            $table->dropColumn('templateType');
        });

        Schema::table('cruise_check_self_task_company_mappings', function (Blueprint $table) {
            $table->dropColumn('shopId');
        });
    }
}
